<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var smallestTrimmedNumbers = function (nums, queries) {
      let res = []
      for (let i = 0, len = queries.length; i < len; i++) {
        const item = queries[i]
        let arr = []
        for (let ind = 0; ind < nums.length; ind++) {
          let str = nums[ind].slice(-item[1])
          arr.push({ str, ind: ind })
        }
        arr.sort((a, b) => {
          return a.str > b.str ? 1 : a.str < b.str ? -1 : 0
        })
        res.push(arr[item[0] - 1].ind)
      }
      return res
    };
    console.log(smallestTrimmedNumbers(["102", "473", "251", "814"], [[1, 1], [2, 3], [4, 2], [1, 2]]));
  </script>
</body>

</html>